<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>采购退货单 - [[${T(com.b2c.erp.DataConfigObject).getInstance().getSysName()}]]</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">
    <style type="text/css">
        .record-box h2 {
            font-weight: bold;
            font-size: 18px;
            margin-bottom: 40px;
        }

        .record-input input {
            width: 400px;
            height: 22px;
            line-height: 22px;
            font-size: 16px;
            padding: 14px 9px;
            border: 1px solid #787878;
        }
    </style>
    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="sp-wrapper">
        <div class="sp-tool">
            <span class="fl">
                <form action="/purchase/purchase_cancel_list" method="get">
                <b><input type="text" id="billNo" name="billNo" autocomplete="off" th:value="${billNo}"
                          placeholder="输入单据编号查询">
                </b>
                    <b>
                    <select name="contactId">
                        <option value="">供应商</option>
                        <option th:each="item:${contacts}" th:value="${item.id}" th:text="${item.name}">入库采购</option>

                    </select>
                </b>
                <b>
                    <select name="transType">
                        <option value="">选择采购类型</option>
                        <option value="PUR_RETURN">采购退货</option>
                        <option value="DaiFaRefund">代发退货</option>
                    </select>
                </b>
                <b><input type="submit" class="button" value="查询"></b>

                    <b>总共：&nbsp;[[${totalSize}]]&nbsp;条记录</b>
                </form>
            </span>
            <span class="fr">
                <a href="/purchase/purchase_cancel" class="add">新增退货单</a>
                <!--                <i id="saomaoruku">扫码入库</i>-->
            </span>
        </div>
        <div class="sp-table">
            <table>
                <thead>
                <tr>
<!--                    <th>序号</th>-->
                    <th>ID</th>
                    <th>单据日期</th>
                    <th>退货单号</th>
                    <th>供应商</th>
                    <th>退货数量</th>
                    <th>退货金额</th>
                    <th>已出库数量</th>
                    <th>审核状态</th>
                    <th>出库状态</th>
                    <th>退款详情</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
<!--                    <td th:text="${itemStat.index+1}">2019-4-11</td>-->
                    <td th:text="${item.id}">2019-4-11</td>
                    <td th:text="${item.getBillDate()}">2019-03-15</td>
                    <td th:text="${item.getBillNo()}">500</td>
                    <td th:text="${item.contactName}">500</td>
                    <td th:text="${item.getTotalQuantity()}">500</td>
                    <td th:text="${#numbers.formatDecimal(item.totalAmount, 1, 2)}">500</td>
                    <td th:text="${item.inQuantity}">500</td>
                    <td>
                        <span th:if="${item.checked == -1}">已拒绝</span>
                        <span th:if="${item.checked == 0}">待审核</span>
                        <span th:if="${item.checked == 1}">已审核</span>
                    </td>
                    <td th:text="*{item.getCheckoutStatus()==1} ? '已全部出库' : '待出库'">500</td>
                    <td >
                        
                        <b th:if="${T(com.b2c.entity.erp.enums.InvoiceHxStateCodeEnum).NoPay.getIndex() ==item.hxStateCode}" style="color: red;">未退款</b>
                        <b th:if="${T(com.b2c.entity.erp.enums.InvoiceHxStateCodeEnum).Paying.getIndex() ==item.hxStateCode}" style="color: rgb(202, 252, 4);">部分退款</b>
                        <b th:if="${T(com.b2c.entity.erp.enums.InvoiceHxStateCodeEnum).Payed.getIndex() ==item.hxStateCode}" style="color: rgb(11, 225, 65);">已退款</b>
                        <a th:if="${T(com.b2c.entity.erp.enums.InvoiceHxStateCodeEnum).Payed.getIndex() != item.hxStateCode}" 
                        th:attr="data-id=${item.getId()},hxAmount=${item.hxAmount},totalAmount=${item.totalAmount}" 
                        class="layui-btn layui-btn-warm layui-btn-sm pay_btn">退款</a>
                    </td>
                    <td>
                        <a th:if="${item.getBillStatus()==0}" th:attr="erpInvoiceId=${item.getId()}"  href="javascript:;" class="purCheck">审核</a>
                        <a th:href="${'/purchase/purchase_cancel_detail?id='+item.id}" >详情</a>
                        <input type="hidden" class="id" th:value="${item.id}">
                        <i class="print" th:attr="data-id=${item.id}">打印</i>
                        <a class="stockIn" th:if="*{item.getCheckoutStatus() != 1 && item.checked == 1}" th:href="${'/purchase/purchase_cancel_detail?id='+item.id}" target="_blank">出库</a>
                    </td>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="pages">
            <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
        </div>
    </div>


    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>

    <style type="text/css">
        .check-box {
            position: relative;
            width: 900px;
            padding: 0 5px;
            font-size: 13px;
            color: #787878;
        }

        .check-info {
            line-height: 40px;
            overflow: hidden;
        }

        .check-info span {
            float: left;
            width: 18%;
            text-align: center;
        }

        .check-info span:nth-child(1) {
            width: 30%;
            text-align: left;
        }

        .check-info span:nth-child(5) {
            width: 16%;
            text-align: right;
        }

        .check-table {
            margin: 10px 0;
            max-height: 250px;
            overflow-y: auto;
        }

        .check-table table {
            width: 100%;
        }

        .check-table th, .check-table td {
            padding: 10px 0;
            font-size: 13px;
            text-align: center;
            border: 1px solid #787878;
        }

        .check-table th {
            padding: 5px 0;
        }
    </style>
    <script type="text/javascript">
        layui.use(['laydate', 'layer'], function () {
            var laydate = layui.laydate;
            var layer = layui.layer;
            //执行一个laydate实例
            $(".print").click(function () {
                var id = $(this).attr("data-id");
                console.log(id);
                //iframe层
                layer.open({
                    type: 2,
                    title: '打印验货单',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['940px', '90%'],
                    content: '/purchase/purchase_cancel_print_detail?id=' + id //iframe的url
                });
            });
        });
        $(function () {
            $('.purCheck').click(function () {
                var id = $(this).attr('erpInvoiceId');
                Tips.confirm({
                    title: '采购审核',
                    content: '您确定要审核通过吗？',
                    define: function () {
                        $.ajax({
                            url: "/ajax_purchase/purchase_check",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify({erpInvoiceId: id,status:1}),
                            success: function (res) {
                                if (res.code == 0) {
                                    location.reload();
                                }
                            },
                            complete: function(XMLHttpRequest){
                                if (XMLHttpRequest.getResponseHeader("REDIRECT")=="NO_ACCESS")alert("无权限访问");
                            },
                        });
                    }
                });
            });

            $(".pay_btn").click(function(){
                var id = $(this).attr("data-id");
                var hxAmount = $(this).attr("hxAmount");
                var totalAmount = $(this).attr("totalAmount");
                
                layer.prompt({
                    formType: 3,
                    value: hxAmount,
                    title: '请输入付款金额'
                }, function(value, index, elem){
                    var hasAm = totalAmount - hxAmount;
                   
                    if(value > hasAm ){
                        layer.alert("支付金额不对");
                    }else{
                        var data = {id:id, payAmount:value};
                        $.ajax({
                            url: "/purchase_ajax/refundAmount",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data:JSON.stringify(data),
                            success: function (res) {

                                if(res.code == 0){
                                    layer.alert(res.msg);
                                    location=location;
                                }else
                                    layer.alert(res.msg);
                            }
                        });
                    }
                });
            });


        });
    </script>
    <!-- end sp-wrapper -->
    <!-- 不同部分 end -->
</div>
</div>
</body>
</html>
